package zip;

import net.jpountz.lz4.*;

public class LZ4Utils {

    public static byte[] compress(String data) {
        LZ4Factory factory = LZ4Factory.fastestInstance();
        LZ4Compressor compressor = factory.fastCompressor();
        return compressor.compress(data.getBytes());
    }

    public static String decompress(byte[] compressedData) {
        LZ4Factory factory = LZ4Factory.fastestInstance();
        LZ4FastDecompressor decompressor = factory.fastDecompressor();
        /* Calculate expected size */
        byte[] decompressedData = new byte[40000];
        int decompressedLength = decompressor.decompress(compressedData, decompressedData);
        return new String(decompressedData, 0, decompressedLength);
    }
}
